<template>
  <div>
    <FormPanel ref="form" :list="formList" :labelPosition="'top'" :labelWidth="130" :cols="3" :isSubmitBtn="false" :collapse="false" />
    <FormPanel ref="form" :list="formList2" :labelPosition="'top'" :labelWidth="130" :cols="3" :isSubmitBtn="false" :collapse="false" />
    <FormPanel :list="followUpFormList" :cols="3" :isSubmitBtn="false" :collapse="false" />
    <FilterTable ref="tableInfo"
                 :columns="columns"
                 :dataSource="tableList"
                 :isMemoryPagination="true"
                 :isSelectColumn="false"
                 height="auto"
                 :onColumnsChange="(columns) => (this.columns = columns)">

    </FilterTable>
    <FormPanel :list="followUpFormList2" :cols="3" :isSubmitBtn="false" :collapse="false" />
    <FilterTable
      ref="tableUp"
      :columns="columnsUp"
      :dataSource="tableListUp"
      :isMemoryPagination="true"
      :isSelectColumn="false"
      height="auto"
      :onColumnsChange="(columns) => (this.columns = columns)"
    >
    </FilterTable>
    <div style="height: 47px"></div>
    <div
      :style="{
        position: 'absolute',
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getDetail } from '@/api/omSaleP/AutoBigOrderRefundAudit/index.js';
import { confirmAction } from '@/utils';
import moment from 'moment';
export default {
  props: {
    type: {
      type: String,
      require: true,
    },
    rowData: {
      type: Object,
    },
  },
  components: {},
  data() {
    return {
      formList: this.createdFrom(),
      formList2: this.createdFrom2(),
      followUpFormList: [
        {
          type: 'BREAK_SPACE',
          label: '区域审核信息',
        },
      ],
      followUpFormList2: [
        {
          type: 'BREAK_SPACE',
          label: '车厂审核信息',
        },
      ],
      columnsUp: this.createdTableUp(),
      columns: this.createdTable(),
      tableList: [],
      tableListUp: [],
      datailData: {},
      demandSeries: [],
      demandModel: [],
    };
  },

  mounted () {
    this.init()
  },
  mixins: [dictionary],
  methods: {
    //初始化页面数据
    async init() {
      const res = await getDetail({id: this.rowData.id});
      let data = {};
      if (res.resultCode === 200) {
        data = res.data;
        this.datailData = res.data;
      }
      this.formList.map(async (x) => {
          // data[x.fieldName].forEach((item) => {
          //   item.name = item.attachmentName;
          //   item.url = item.attachmentUrl;
          //   item.uid = item.attachmentUuid;
          // });
          //
        x.initialValue = data[x.fieldName];
      });
      this.formList2.map(async (x) => {

        x.initialValue = data[x.fieldName];
      });
      if(res.data.areaList != null){
        this.$refs.tableInfo.EXECUTE_INSERT(res.data.areaList)
      };
      if(res.data.depotList != null){
        this.$refs.tableUp.EXECUTE_INSERT(res.data.depotList)
      }
    },



    //保存， 提交, 关闭
    async closeDrawer(type) {
      if(type==1){
        this.$emit('close')
      }else if(type==2){
        this.$refs.from.SUBMIT_FORM();
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          json.id=this.rowData.id;
          json.applyStatus=60121004;
          let res = await updateAllocateApply(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '驳回成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }
      }else{
        let str=this.formList.find(x=>x.fieldName=='checkDesc').initialValue;
        let json =str?{checkDesc:str}:{}
        json.id=this.rowData.id;
        json.applyStatus=60121003;
        let res = await updateAllocateApply(json);
        if (res.resultCode == 200) {
          this.$notify({
            title: '成功',
            message: '通过成功',
            type: 'success'
          });
          this.$emit('close', json);
        }
      }
    },

    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '申请信息',
        },
        {
          type: 'INPUT',
          label: '申请经销商',
          fieldName: 'dealerName',//DEALER_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '归属区域',
          fieldName: 'regional',//REGIONAL
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '区域经理',
          fieldName: 'regionalManager',//REGIONAL_MANAGER
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '申请人',
          fieldName: 'applyPersonName',//APPLY_PERSON_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '联系方式',
          fieldName: 'applyMobile',//APPLY_MOBILE
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '申请时间',
          fieldName: 'applyRefundTime',//APPLY_REFUND_TIME
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '申请理由',
          fieldName: 'applyReason',//APPLY_REFUND_TIME
          disabled: true,
          selfCols:3,
          rows:3
        },

      ];
    },
    createdFrom2() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '大定订单信息',
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',//CUSTOMER_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '客户手机号',
          fieldName: 'customerMobile',//CUSTOMER_MOBILE
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '预订单号',
          fieldName: 'wishApplyNo',//WISH_APPLY_NO
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '大定金额',
          fieldName: 'largeFixedAmount',//LARGE_FIXED_AMOUNT
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '支付时间',
          fieldName: 'paymentTime',//ORDERS_TIME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'seriesName',//SERIES_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',//MODEL_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '配置',
          fieldName: 'packageName',//PACKAGE_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '选装',
          fieldName: 'optionName',//OPTION_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimName',//TRIM_NAME
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '外观',
          fieldName: 'guiseName',//GUISE_NAME
          disabled: true,
        },

      ];
    },

    createdTable() {
      return [
        //区域审核信息
        {
          title: '审核时间',
          dataIndex: 'areaRauditTime', //AREA_RAUDIT_TIME
          sorter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
        },
        {
          title: '审核人',
          dataIndex: 'areaAuditBy',  //AREA_AUDIT_BY
          sorter: true,
        },
        {
          title: '审核结果',
          dataIndex: 'reaAuditType', //REA_AUDIT_TYPE
          sorter: true,
          editItems:this.createDictList('2158'),
          render: (props) => {
            let text = this.createDictText(props.row.reaAuditType,'2158');
            if(text == '待车厂审核'){
              text = '区域审核通过'
            }
            return <span>{text}</span>;
          },
        },
        {
          title: '审核意见',
          dataIndex: 'areaAuditOpinion',//AREA_AUDIT_OPINION
          sorter: true,
        },

      ];
    },
    createdTableUp() {
      return [
        //车厂审核信息
        {
          title: '审核时间',
          dataIndex: 'factoryRauditTime',//FACTORY_RAUDIT_TIME
          sorter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
        },

        {
          title: '审核人',
          dataIndex: 'factoryAuditBy',//FACTORY_AUDIT_BY
          sorter: true,
        },
        {
          title: '审核结果',
          dataIndex: 'factoryAuditType',//FACTORY_AUDIT_TYPE  APPLY_TYPE
          sorter: true,
          editItems:this.createDictList('2158'),

        },
        {
          title: '审核意见',
          dataIndex: 'factoryAuditOpinion',//FACTORY_AUDIT_OPINION
          sorter: true,
        },
      ];
    },
  },
};
</script>
<style lang="scss">
.footer {
  position: 'absolute';
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 9;
  border-top: '1px solid #e9e9e9';
  padding: '10px 20px';
  background: '#fff';
  text-align: 'right';
  box-sizing: border-box;
  display: flex;
  justify-content: space-around;
}
.upload-btn {
  width: 100%;
}
.el-upload-list__item-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding-right: 20px;
  box-sizing: border-box;
}
</style>
